<?php
class ControllerGender { 

    function getFunction($op){
        
        switch ($op) {
            case "new":
                $this->newGender();
                break;
            
            case "list":
                $this->listGender();
                break;
            
            case "save":
                $this->saveGender();
                break;

            case "edit":
                $this->editGender();
                break;
            
            case "update":
                $this->updateGender();
                break;
            
            case "del":
                $this->deleteGender();
                break;
            
            case "combo":
                return $this->comboGender();
                break;
            
            default:
                echo "ERROR NO HAY CONTROLADOR PARA ESA OPCION";
                break;
        }
    }
    

    function newGender(){
        include_once "vista/vista.gender.php";
        form_gender();
    }    
    

    function saveGender(){
        include_once "modelo/modelo.gender.php";
        
        $g = new gender();
        $g->set_g_id($_REQUEST["g_id"]); 
        $g->set_g_desc($_REQUEST["g_desc"]); 
        $g->set_g_status($_REQUEST["g_status"]); 

        
        if($g->Save()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_save_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_save_error']." </div>";
        }
        $this->listGender($msj);
        
    }    
    
    function editGender(){
        include_once 'modelo/modelo.gender.php';
        include_once 'vista/vista.gender.php';
        
        $g = new gender();
        $g->setg_id($_REQUEST["g_id"]); 
        
        $g->getData();
        
        form_gender($g);
        
    }    
    
    function deleteGender(){
        include_once 'modelo/modelo.gender.php';
        
        $g = new gender();
        $g->setg_id($_REQUEST["g_id"]); 
        
        if($g->Delete()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_delete_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_delete_error']." </div>";
        }
        $this->listGender($msj);
    }

    
    function updateGender(){
        include_once 'modelo/modelo.gender.php';
        
        $g = new gender();
        $g->set_g_id($_REQUEST["g_id"]); 
        $g->set_g_desc($_REQUEST["g_desc"]); 
        $g->set_g_status($_REQUEST["g_status"]); 

        if($g->Update()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_update_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_update_error']." </div>";
        }
        $this->listGender($msj);
    }

    
    function listGender($msj=false){
        include_once 'modelo/modelo.gender.php';
        include_once 'vista/vista.gender.php';
        
        $g = new gender();

        $g->setg_id($_REQUEST["g_id"]); 
        $g->getData();
        
        $dataTotal = $g->GetList(" count(*) ", false,  true);
        $dataTotal = $dataTotal[0][0]; 
        $data = $g->GetList(" * ", false);
        if(is_null($data)){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_empty_error']." </div>";
        }
        list_gender($data, $msj, $dataTotal);

    }

}